<template>
  <div class="consultation-room">
    <div class="room-header">
      <h2>会诊房间 - {{ roomId }}</h2>
      <div class="room-actions">
        <el-button type="danger" @click="handleLeave">离开会诊</el-button>
      </div>
    </div>
    
    <el-row :gutter="20">
      <!-- 视频通话区域 -->
      <el-col :span="16">
        <el-card shadow="never" class="video-area">
          <div class="video-container">
            <div class="main-video">
              <div class="video-placeholder">
                <el-icon size="64"><VideoCamera /></el-icon>
                <p>主视频区域</p>
              </div>
            </div>
            <div class="participant-videos">
              <div v-for="i in 4" :key="i" class="participant-video">
                <div class="video-placeholder small">
                  <el-icon size="24"><User /></el-icon>
                  <p>参与者{{ i }}</p>
                </div>
              </div>
            </div>
          </div>
          
          <div class="video-controls">
            <el-button-group>
              <el-button :type="micEnabled ? 'primary' : 'danger'" @click="toggleMic">
                <el-icon><Microphone /></el-icon>
              </el-button>
              <el-button :type="cameraEnabled ? 'primary' : 'danger'" @click="toggleCamera">
                <el-icon><VideoCamera /></el-icon>
              </el-button>
              <el-button type="info" @click="toggleScreen">
                <el-icon><Monitor /></el-icon>
              </el-button>
            </el-button-group>
          </div>
        </el-card>
      </el-col>
      
      <!-- 右侧功能区 -->
      <el-col :span="8">
        <!-- 文件共享 -->
        <el-card shadow="never" class="file-share">
          <template #header>
            <span>文件共享</span>
          </template>
          <el-upload
            drag
            action="#"
            :before-upload="handleFileUpload"
          >
            <el-icon class="el-icon--upload"><UploadFilled /></el-icon>
            <div class="el-upload__text">
              将文件拖到此处，或<em>点击上传</em>
            </div>
          </el-upload>
          
          <div class="shared-files">
            <div v-for="file in sharedFiles" :key="file.id" class="file-item">
              <el-icon><Document /></el-icon>
              <span>{{ file.name }}</span>
            </div>
          </div>
        </el-card>
        
        <!-- AI会议纪要 -->
        <el-card shadow="never" class="ai-notes">
          <template #header>
            <span>AI会议纪要</span>
          </template>
          <div class="notes-content">
            <p v-for="note in aiNotes" :key="note.id">{{ note.content }}</p>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { 
  VideoCamera, User, Microphone, 
  Monitor, UploadFilled, Document 
} from '@element-plus/icons-vue'

const route = useRoute()
const router = useRouter()
const roomId = route.params.id as string

const micEnabled = ref(true)
const cameraEnabled = ref(true)

const sharedFiles = ref([
  { id: 1, name: '患者检查报告.pdf' },
  { id: 2, name: '影像资料.jpg' }
])

const aiNotes = ref([
  { id: 1, content: '会诊开始，参与科室：内科、肿瘤科' },
  { id: 2, content: '讨论患者张三的治疗方案' }
])

const toggleMic = () => {
  micEnabled.value = !micEnabled.value
  ElMessage.info(micEnabled.value ? '麦克风已开启' : '麦克风已关闭')
}

const toggleCamera = () => {
  cameraEnabled.value = !cameraEnabled.value
  ElMessage.info(cameraEnabled.value ? '摄像头已开启' : '摄像头已关闭')
}

const toggleScreen = () => {
  ElMessage.info('屏幕共享功能')
}

const handleFileUpload = (file: File) => {
  ElMessage.success(`文件 ${file.name} 上传成功`)
  return false
}

const handleLeave = () => {
  router.go(-1)
}

onMounted(() => {
  console.log('进入会诊房间:', roomId)
})
</script>

<style lang="scss" scoped>
.consultation-room {
  height: calc(100vh - 140px);
  
  .room-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    
    h2 {
      margin: 0;
      color: #303133;
    }
  }
  
  .video-area {
    height: 500px;
    
    .video-container {
      height: 420px;
      
      .main-video {
        height: 320px;
        background: #f5f5f5;
        border-radius: 8px;
        margin-bottom: 16px;
        
        .video-placeholder {
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          height: 100%;
          color: #909399;
        }
      }
      
      .participant-videos {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        height: 80px;
        
        .participant-video {
          background: #f5f5f5;
          border-radius: 4px;
          
          .video-placeholder.small {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100%;
            font-size: 12px;
            color: #909399;
            
            p {
              margin: 4px 0 0 0;
            }
          }
        }
      }
    }
    
    .video-controls {
      text-align: center;
      margin-top: 16px;
    }
  }
  
  .file-share {
    margin-bottom: 20px;
    
    .shared-files {
      margin-top: 16px;
      
      .file-item {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px;
        border-radius: 4px;
        margin-bottom: 8px;
        background: #f8f9fa;
        
        span {
          font-size: 14px;
          color: #606266;
        }
      }
    }
  }
  
  .ai-notes {
    .notes-content {
      max-height: 200px;
      overflow-y: auto;
      
      p {
        font-size: 14px;
        color: #606266;
        line-height: 1.5;
        margin-bottom: 8px;
        padding: 8px;
        background: #f8f9fa;
        border-radius: 4px;
      }
    }
  }
}
</style>